package com.miao.advice;

import com.miao.enums.REnum;
import com.miao.exception.BusinessException;
import com.miao.util.JSONResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class BusinessExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public JSONResponse handleBusinessException(BusinessException e) {
//        return new JSONResponse(e.getCode(), e.getMessage(), null);
        e.printStackTrace();
        return JSONResponse.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public JSONResponse handleException(Exception e) {
        e.printStackTrace();
        return JSONResponse.error(REnum.UNKNOW_ERROR.getCode(), e.getMessage());
    }
}
